using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using LeadTracker.EFCodeFirst.Entities;

namespace LeadTracker.EFCodeFirst.Mapping
{
	public class LeadMap : EntityTypeConfiguration<Lead>
	{
		public LeadMap()
		{
			// Primary Key
			this.HasKey(t => t.LeadKey);

			// Properties
			this.Property(t => t.Title)
				.IsRequired()
				.HasMaxLength(127);
				
			// Table & Column Mappings
			this.ToTable("Lead");
			this.Property(t => t.LeadKey).HasColumnName("LeadKey");
			this.Property(t => t.Title).HasColumnName("Title");
			this.Property(t => t.CreatedByKey).HasColumnName("CreatedByKey");
			this.Property(t => t.CreatedDate).HasColumnName("CreatedDate");
			this.Property(t => t.LeadTypeKey).HasColumnName("LeadTypeKey");

			// Relationships
			this.HasRequired(t => t.Editor)
				.WithMany(t => t.Leads)
				.HasForeignKey(d => d.CreatedByKey);
				
			this.HasRequired(t => t.LeadType)
				.WithMany(t => t.Leads)
				.HasForeignKey(d => d.LeadTypeKey);
				
		}
	}
}

